<template>
  <div class="mv-container">
    <div class="mv-wrap">
      <h3 class="title">mv详情</h3>
      <!-- mv -->
      <div class="video-wrap">
        <video controls :src="url" autoplay></video>
      </div>
      <!-- mv信息 -->
      <div class="info-wrap">
        <div class="singer-info">
          <div class="avatar-wrap">
            <img :src="icon+'?param=250y150'" alt="" />
          </div>
          <span class="name">{{ mvInfo.artistName }}</span>
        </div>
        <div class="mv-info">
          <h2 class="title">{{ mvInfo.name }}</h2>
          <span class="date">发布：{{ mvInfo.publishTime }}</span>
          <span class="number">播放：{{ mvInfo.playCount }} 次</span>
          <p class="desc">
            {{ mvInfo.desc }}
          </p>
        </div>
      </div>
      <!-- 精彩评论 -->
      <div class="comment-wrap" v-if="hotComments !== undefined && hotComments.length !== 0">
        <p class="title">
          精彩评论<span class="number">({{ hotComments.length }})</span>
        </p>
        <div class="comments-wrap">
          <!-- 评论 -->
          <div class="item" v-for="(item, index) in hotComments" :key="index">
            <div class="icon-wrap">
              <!-- 头像 -->
              <img :src="item.user.avatarUrl+'?param=50y50'" alt="" />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{ item.user.nickname }}</span>
                <span class="comment">：{{ item.content }}</span>
              </div>
              <!-- 回复 -->
              <div class="re-content" v-if="item.beReplied.length !== 0">
                <span class="name">{{ item.beReplied[0].user.nickname }}</span>
                <span class="comment">：{{ item.beReplied[0].content }}</span>
              </div>
              <div class="date">{{ item.time | dateFormat }}</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 最新评论 -->
      <div class="comment-wrap">
        <p class="title">
          最新评论<span class="number">({{ total }})</span>
        </p>
        <div class="comments-wrap">
          <!-- 评论 -->
          <div class="item" v-for="(item, index) in comments" :key="index">
            <div class="icon-wrap">
              <!-- 头像 -->
              <img :src="item.user.avatarUrl+'?param=50y50'" alt="" />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{ item.user.nickname }}</span>
                <span class="comment">：{{ item.content }}</span>
              </div>
              <!-- 回复 -->
              <div class="re-content" v-if="item.beReplied.length !== 0">
                <span class="name">{{ item.beReplied[0].user.nickname }}</span>
                <span class="comment">：{{ item.beReplied[0].content }}</span>
              </div>
              <div class="date">{{ item.time | dateFormat }}</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 分页器 -->
      <el-pagination @current-change="handleCurrentChange" background layout="prev, pager, next" :total="total" :current-page="page" :page-size="pageSize">
      </el-pagination>
    </div>
    <div class="mv-recommend">
      <h3 class="title">相关推荐</h3>
      <div class="mvs">
        <div class="items">
          <div class="item" v-for="(item, index) in simiMvs" :key="index" @click="playMv(item.id)">
            <div class="img-wrap">
              <img :src="item.cover+'?param=250y150'" alt="" />
              <span class="el-icon-video-play icon-play"></span>
              <div class="num-wrap">
                <div class="el-icon-video-play icon-play"></div>
                <div class="num">{{ item.playCount  }}</div>
              </div>
              <span class="time">{{ item.duration  }}</span>
            </div>
            <div class="info-wrap">
              <div class="name">{{ item.name }}</div>
              <div class="singer">{{ item.artistName }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
    data(){
        return{
            id: this.$route.query.q,
            total: 20,// 总条数
            page: 1,// 页码
            pageSize: 10, // 页容量
            url: '',// mv地址
            mvInfo: {},//mv的信息
            simiMvs: [],//相关mv
            icon: '',//歌手头像
            hotComments: [],
            comments: []
        }
    },
    created(){
     this.getMv()//获取mv播放地址
     this.simiMv()//相关mv
     this.getMvInfo()//获取mv的信息
     this.getComment()//获取品论信息
     this.newComment()
    },
    methods:{
        handleCurrentChange(val){

        },
        playMv(id){
          this.id = id
          this.getMv()
        },
        //获取mv播放地址
        getMv(){
            axios({
                url:'https://autumnfish.cn/mv/url',
                method:'GET',
                params:{
                    id:this.id
                }
            }).then(res=>{
                console.log(res)
                this.url = res.data.data.url
            })
        },
        //相关mv
        simiMv(){
            axios({
                url:'https://autumnfish.cn/simi/mv',
                method:'GET',
                params:{
                  mvid:this.$route.query.q
                }
            }).then(res=>{
                this.simiMvs = res.data.mvs
            })
        },
        //获取mv的信息
        getMvInfo(){
            axios({
                url:'https://autumnfish.cn/mv/detail',
                method:'GET',
                params:{
                 mvid:this.id
                }
            }).then(res=>{
               this.mvInfo = res.data.data
            //获取歌手信息
            let id = this.mvInfo.artists[0].id
            this.getSongInfo(id)
            })
        },
        //歌手信息
        getSongInfo(id){
            axios({
                url:'https://autumnfish.cn/artists',
                method:'GET',
                params:{
                  id
                }
            }).then(res=>{
                this.icon = res.data.artist.picUrl
            })
        },
         //获取评论
        getComment(){
             axios({
               url:'https://autumnfish.cn/comment/hot',
               method:'GET',
               params:{
                id:this.id,
                type:2
               }
             }).then(res=>{
               console.log(res)
               this.hotComments = res.data.hotComments
               //保存个数
               this.total = res.data.total
             })
        },
        newComment(){
            axios({
              url:'https://autumnfish.cn/comment/playlist',
              method:'GET',
              params:{
                id:this.id,
                limit:10,
                offset:(this.page-1)*10
              }
            }).then(res=>{
              //总个数
              this.total = res.data.total
              //品论数据
              this.comments = res.data.comments
            })
        }

    }
}
</script>

<style lang="scss" scoped>
.mv-container {
    display: flex;
    .title {
        margin-bottom: 20px;
    }
    .mv-wrap {
        width: 800px;
        margin-right: 35px;
        .date {
            margin-right: 25px;
        }
        .video-wrap {
            width: 100%;
            height: 390px;
            margin-bottom: 20px;
            video {
                border-radius: 5px;
                height: 100%;
                width: 100%;
                outline: none;
            }
        }
        .info-wrap {
            margin-bottom: 50px;
            .singer-info {
                display: flex;
                align-items: center;
                margin-bottom: 35px;
                .avatar-wrap {
                    width: 70px;
                    height: 70px;
                    border-radius: 50%;
                    margin-right: 10px;
                    overflow: hidden;
                    img {
                        height: 100%;
                    }
                }
            }
            .mv-info {
                .title {
                    font-size: 30px;
                }
                .desc {
                    font-size: 15px;
                    margin-top: 20px;
                }
            }
        }
        .comment-wrap {
            margin-bottom: 70px;
            .title {
                font-size: 25px;
                .number {
                    color: black;
                    font-size: 20px;
                }
            }
            .item {
                display: flex;
                padding-top: 20px;
                .icon-wrap {
                    margin-right: 15px;
                    img {
                        width: 50px;
                        height: 50px;
                        border-radius: 50%;
                    }
                }
                &:not(:last-child) {
                    .content-wrap {
                        border-bottom: 1px solid #f2f2f1;
                    }
                }
                .content-wrap {
                    padding-bottom: 20px;
                    flex: 1;
                    .name {
                        color: #517eaf;
                        font-size: 14px;
                    }
                    .comment {
                        font-size: 14px;
                    }
                    .re-content {
                        padding: 10px;
                        background-color: #e6e5e6;
                        border-radius: 5px;
                    }
                }
            }
        }
    }
    .mv-recommend {
        flex: 1;
        .mvs {
            .items {
                display: flex;
                flex-wrap: wrap;
                .item {
                    cursor: pointer;
                    width: 100%;
                    display: flex;
                    align-items: center;
                    padding: 10px;
                    cursor: pointer;
                    &:hover {
                        background-color: #f5f5f5;
                    }
                    .img-wrap {
                        width: 180px;
                        position: relative;
                        margin-right: 10px;
                        & > .icon-play {
                            position: absolute;
                            top: 50%;
                            left: 50%;
                            transform: translate(-50%, -50%);
                            width: 40px;
                            height: 40px;
                            color: #dd6d60;
                            font-size: 20px;
                            border-radius: 50%;
                            display: flex;
                            align-items: center;
                            justify-content: center;
                            background: rgba(255, 255, 255, 0.8);
                            opacity: 0;
                            &::before {
                                transform: translateX(1px);
                            }
                        }
                        &:hover {
                            & > .icon-play {
                                opacity: 1;
                            }
                        }
                        img {
                            width: 100%;
                            border-radius: 5px;
                        }
                        .num-wrap {
                            position: absolute;
                            color: white;
                            top: 0;
                            right: 0;
                            display: flex;
                            align-content: center;
                            font-size: 15px;
                            padding-right: 5px;
                            padding-top: 2px;
                            .icon-play {
                                font-size: 12px;
                                display: flex;
                                align-items: center;
                                margin-right: 5px;
                            }
                        }
                        .time {
                            position: absolute;
                            bottom: 5px;
                            right: 5px;
                            color: white;
                            font-size: 15px;
                        }
                    }
                    .info-wrap {
                        flex: 1;
                        .name {
                            font-size: 15px;
                        }
                        .singer {
                            font-size: 14px;
                            color: #c5c5c5;
                        }
                    }
                }
            }
        }
    }
}
.mv-container .mv-wrap .date,
.mv-container .mv-wrap .number {
    color: #bebebe;
    font-size: 14px;
}
.mv-container .mv-wrap .comment-wrap .item .content-wrap .content,
.mv-container .mv-wrap .comment-wrap .item .content-wrap .re-content {
    margin-bottom: 10px;
}

</style>